package com.autonavi.yunda.yunji.core.engine.exception;

import com.autonavi.yunda.yunji.common.exception.AmapException;
import com.autonavi.yunda.yunji.common.exception.AmapExceptionCode;

/**
 * @author wangchunsheng
 * @date 2021/08/16
 */
public class EnginePreconditions {
    private EnginePreconditions() {
    }

    public static void check(Object expression, String code, String message) {
        if (expression instanceof Boolean) {
            if (!(Boolean) expression) {
                throw new EngineException(code, message);
            }
        } else {
            throw new AmapException(AmapExceptionCode.COMMON_ILLEGAL_PARAM, "expression表达式返回必须为true或者false");
        }

    }

    public static void check(Object expression, String message) {
        check(expression, AmapExceptionCode.COMMON_ILLEGAL_PARAM.getCode() + "", message);
    }

    public static void checkArg(boolean expression) {
        check(expression, AmapExceptionCode.COMMON_ILLEGAL_PARAM.getCode() + "", AmapExceptionCode.COMMON_ILLEGAL_PARAM.getText());
    }

}
